package com.cdck.safe.dete.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdck.safe.dete.common.result.PageResult;
import com.cdck.safe.dete.common.result.Result;
import com.cdck.safe.dete.model.bo.ResourceBO;
import com.cdck.safe.dete.model.bo.SeatBO;
import com.cdck.safe.dete.model.entity.Resource;
import com.cdck.safe.dete.model.query.BaseKeywordsQuery;
import com.cdck.safe.dete.model.vo.*;
import com.cdck.safe.dete.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
 * (Resource)表控制层
 *
 * @author wp
 * @since 2024-05-18 14:33:03
 */
@Api(value = "resource")
@RestController
@RequestMapping("resource")
@RequiredArgsConstructor
public class ResourceController {

    private final ResourceService resourceService;


    @ApiOperation(value = "分页列表")
    @GetMapping("/page")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "queryParams"  ,value ="查询条件" )
    })
    public PageResult<ResourceVO> queryByPage(BaseKeywordsQuery queryParams) {
        IPage<ResourceVO> result = resourceService.queryByPage(queryParams);
        return PageResult.success(result);

    }

    @ApiOperation(value = "表单数据")
    @GetMapping("/{id}/form")
    public Result<Resource> getResourceForm(
           @PathVariable Long id
    ) {
        Resource formData = resourceService.getResourceFormData(id);
        return Result.success(formData);
    }


    /**
     * 新增数据
     *
     * @param resource 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增")
    @PostMapping
    public Result add(
        @RequestBody @Valid
        Resource resource
        ) {
        boolean result = this.resourceService.saveResource(resource);
        return Result.judge(result);
    }

    @ApiOperation(value = "修改")
    @PutMapping(value = "/{id}")
    public Result updateResource(
            @PathVariable Long id,
            @RequestBody @Validated Resource resource) {
        boolean result = resourceService.updateResource(id, resource);
        return Result.judge(result);
    }


    @ApiOperation(value = "删除数据")
    @DeleteMapping("/{ids}")
    public Result deleteResources(
             @PathVariable String ids
    ) {
        boolean result = resourceService.deleteResources(ids);
        return Result.judge(result);
    }

    @ApiOperation(value = "获取实验室资源状态")
    @PostMapping("/status")
    public Result<List<ResourceStatusVO>> getSeatListByLabId(@RequestBody ResourceBO resourceBO) {
        List<ResourceStatusVO> result = resourceService.getResourceStatus(resourceBO);
        return Result.success(result);
    }

    @ApiOperation(value = "获取预约申请分页列表")
    @GetMapping("/application/page")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "queryParams", value = "查询条件")
    })
    public PageResult<ResourceRecordVO> getApplicationPage(BaseKeywordsQuery queryParams) {
        IPage<ResourceRecordVO> result = resourceService.getApplicationPage(queryParams);
        return PageResult.success(result);

    }
}

